package us.gaaoc.framework.util;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import sun.misc.BASE64Encoder;
import sun.misc.CharacterEncoder;

public class Encrypt {
	
	private static Encrypt instance;
	
	public Encrypt(){
		
	}
	
	public static String encrypt(String plaintext)  {
		
	    MessageDigest md = null;
	    try{
	      md = MessageDigest.getInstance("SHA"); 
	    } catch(NoSuchAlgorithmException e){}
	    try{
	      md.update(plaintext.getBytes("UTF-8"));
	    } catch(UnsupportedEncodingException e){}

	    byte raw[] = md.digest(); 
	    String hash = (new BASE64Encoder()).encode(raw); 
	    return hash; 
	  }
	  
	 public static synchronized Encrypt getInstance() {
		 
		 if(instance == null) {
			 instance = new Encrypt(); 
		 }
		 return instance;
	 }

	
}
